﻿using System;
using System.Collections.Generic;
using System.Linq; 
using System.Text;

namespace Xcap
{
    using System.Xml.Linq;

    namespace Xml
    {


        #region enumerations

    
        /// <summary>
        /// Records the user-input or usage state of the service or device (more info in RFC 4480).
        /// </summary>
        public enum xcapRpidUserInput
        {
            active,
            idle
        }

        /// <summary>
        /// Designates the current state and role that the person plays.
        /// </summary>
        public enum xcapRpidSphere
        {
            home,
            work,
            unknown
        }

        /// <summary>
        /// Describes where an entity is located (RFC 4589)
        /// </summary>
        public enum xcapLocationTypes
        {
            /// <summary>
            /// A device that is used or intended to be used for flight in the air, such as an airplane, helicopter, gyroplane, glider, or lighter-than-air devices like a balloon.
            /// </summary>
            aircraft,
            /// <summary>
            /// A place from which aircrafts operate, such as an airport or airport, heliport.
            /// </summary>
            airport,
            /// <summary>
            /// Enclosed area used for sports events.
            /// </summary>
            arena,
            /// <summary>
            /// An automotive vehicle, usually four-wheeled, designed for passenger transportation, such as a car.
            /// </summary>
            automobile,
            /// <summary>
            /// Business establishment in which money is kept for saving, commercial purposes, is invested, supplied for loans, or exchanged.
            /// </summary>
            bank,
            /// <summary>
            /// A bar or saloon.
            /// </summary>
            bar,
            /// <summary>
            /// A vehicle with two wheels tandem, a steering handle, a saddle seat, and pedals by which it is propelled.
            /// </summary>
            bicycle,
            /// <summary>
            /// A large motor vehicle designed to carry passengers.
            /// </summary>
            bus,
            /// <summary>
            /// Terminal that serves bus passengers, such as a bus depot or bus terminal.
            /// </summary>
            bus_station, //NOT IMPLEMENTED
            /// <summary>
            /// Usually a small and informal establishment that serves various refreshments (such as coffee); coffee shop.
            /// </summary>
            cafe,
            /// <summary>
            /// Academic classroom or lecture hall.
            /// </summary>
            classroom,
            /// <summary>
            /// Dance club, nightclub, or discotheque.
            /// </summary>
            club,
            /// <summary>
            /// Construction site.
            /// </summary>
            construction,
            /// <summary>
            /// Convention center or exhibition hall.
            /// </summary>
            convention_center,
            /// <summary>
            /// Government building, such as those used by the legislative, executive, or judicial branches of governments, including court houses, police stations, and military installations.
            /// </summary>
            government,
            /// <summary>
            /// Hospital, hospice, medical clinic, mental institution, or doctor's office.
            /// </summary>
            hospital,
            /// <summary>
            /// Hotel, motel, inn, or other lodging establishment.
            /// </summary>
            hotel,
            /// <summary>
            /// Industrial setting, such as a manufacturing floor or power plant.
            /// </summary>
            industrial,
            /// <summary>
            /// Library or other public place in which literary and artistic materials, such as books, music, periodicals, newspapers, pamphlets, prints, records, and tapes, are kept for reading, reference, or lending.
            /// </summary>
            library,
            /// <summary>
            /// A two-wheeled automotive vehicle, including a scooter.
            /// </summary>
            motorcycle,
            /// <summary>
            /// Business setting, such as an office.
            /// </summary>
            office,
            /// <summary>
            /// A place without a registered place type representation.
            /// </summary>
            other,
            /// <summary>
            /// Outside a building, in or into the open air, such as a park or city streets.
            /// </summary>
            outdoors,
            /// <summary>
            /// A parking lot or parking garage.
            /// </summary>
            parking,
            /// <summary>
            /// A religious site where congregations gather for religious observances, such as a church, chapel, meetinghouse, mosque, shrine, synagogue, or temple.
            /// </summary>
            place_of_worship,
            /// <summary>
            /// Correctional institution where persons are confined while on trial or for punishment, such as a prison, penitentiary, jail, brig.
            /// </summary>
            prison,
            /// <summary>
            /// Public area such as a shopping mall, street, park, public building, train station, or airport or in public conveyance such as a bus, train, plane, or ship.  This general description encompasses the more precise descriptors 'street', 'public-transport', 'aircraft', 'bus', 'bus-station', 'train', 'train-station', 'airport', 'shopping-area', 'outdoors', and 'watercraft'.
            /// </summary>
            _public,
            /// <summary>
            /// Any form of public transport, including aircraft, bus, train, or ship.
            /// </summary>
            public_transport,
            /// <summary>
            /// A private or residential setting, not necessarily the personal residence of the entity, e.g., including a friend's home.
            /// </summary>
            residence,
            /// <summary>
            /// Restaurant, coffee shop, or other public dining establishment.
            /// </summary>
            restaurant,
            /// <summary>
            /// School or university property, but not necessarily a classroom or library.
            /// </summary>
            school,
            /// <summary>
            /// Shopping mall or shopping area.  this area is a large, often enclosed, shopping complex containing various stores, businesses, and restaurants usually accessible by common passageways.
            /// </summary>
            shopping_area,
            /// <summary>
            /// Large, usually open structure for sports events, including a racetrack.
            /// </summary>
            stadium,
            /// <summary>
            /// Place where merchandise is offered for sale, such as a shop.
            /// </summary>
            store,
            /// <summary>
            /// A public thoroughfare, such as an avenue, street, alley, lane, or road, including any sidewalks.
            /// </summary>
            street,
            /// <summary>
            /// Theater, lecture hall, auditorium, classroom, movie theater, or similar facility designed for presentations, talks, plays, music performances, and other events involving an audience.
            /// </summary>
            theater,
            /// <summary>
            /// Train, monorail, maglev, cable car, or similar conveyance.
            /// </summary>
            train,
            /// <summary>
            /// Terminal where trains load or unload passengers or goods; railway station, railroad station, railroad terminal, train depot.
            /// </summary>
            train_station,
            /// <summary>
            /// An automotive vehicle suitable for hauling, used primarily to carry goods rather than people.
            /// </summary>
            truck,
            /// <summary>
            /// In a land-, water-, or aircraft that is underway (in-motion).
            /// </summary>
            underway,
            /// <summary>
            /// The type of place is unknown.
            /// </summary>
            unknown,
            /// <summary>
            /// Place in which goods or merchandise are stored, such as a storehouse or self-storage facility.
            /// </summary>
            warehouse,
            /// <summary>
            /// In, on, or above bodies of water, such as an ocean, lake, river, canal, or other waterway.
            /// </summary>
            water,
            /// <summary>
            /// On a vessel for travel on water such as a boat or ship.
            /// </summary>
            watercraft
        }

        /// <summary>
        /// Indicates which types of communication third parties are unlikely
        /// to be able to intercept.
        /// </summary>
        public enum xcapRpidPrivacy
        {
            /// <summary>
            /// Inappropriate individuals are not likely to overhear audio communications.
            /// </summary>
            audio,
            /// <summary>
            /// Inappropriate individuals are not likely to see video communications.
            /// </summary>
            video,
            /// <summary>
            /// Inappropriate individuals are not likely to see text communications.
            /// </summary>
            text,
            /// <summary>
            /// This information is unknown.
            /// </summary>
            unknown
        }

        /// <summary>
        /// Supported presence element child elements in PIDF
        /// </summary>
        public enum xcapPidfSupportedElements
        {
            presence,
            tuple,
            person,
            device,
            note,
            timestamp
        }

        /// <summary>
        /// Supported resource lists elements child elements
        /// </summary>
        public enum xcapResourceListsSupportedElements
        {
            resource_lists,
            list,
            entry,
            //entry_ref, not impl. 
            display_name,
            //external,  not impl.
        }

        public enum xcapPresRulesSupportedElements
        {
            ruleset,
            rule,
            conditions,
            identity,
            one,
            actions,
            sub_handling,
            transformations,
            provide_services,
            provide_persons,
            provide_devices
        }

        public enum xcapPresRulesActions
        { 
            allow,
            block,
            confirm,
            polite_block
        }

        public enum xcapPresRulesProvideServices
        {
            
        }

        /// <summary>
        /// Supported rpid moods (specified in RFC 4480)
        /// </summary>
        public enum xcapRpidMood
        {
            afraid,
            amazed,
            angry,
            annoyed,
            anxious,
            ashamed,
            bored,
            brave,
            calm,
            cold,
            confused,
            contented,
            cranky,
            curious,
            depressed
                ,
            disappointed
                ,
            disgusted
                ,
            distracted
                ,
            embarrassed
                ,
            excited
                ,
            flirtatious
                ,
            frustrated
                ,
            grumpy
                ,
            guilty
                ,
            happy
                ,
            hot
                ,
            humbled
                ,
            humiliated
                ,
            hungry
                ,
            hurt
                ,
            impressed
                ,
            in_awe
                ,
            in_love
                ,
            indignant
                ,
            interested
                ,
            invincible
                ,
            jealous
                ,
            lonely
                ,
            mean
                ,
            moody
                ,
            nervous
                ,
            neutral
                ,
            offended
                ,
            other
                ,
            playful
                ,
            proud
                ,
            relieved
                ,
            remorseful
                ,
            restless
                ,
            sad
                ,
            sarcastic
                ,
            serious
                ,
            shocked
                ,
            shy
                ,
            sick
                ,
            sleepy
                ,
            stressed
                ,
            surprised
                ,
            thirsty
                ,
            unknown
                , worried
        }

        /// <summary>
        /// Supported rpid activities (specified in RFC 4480)
        /// </summary>
        public enum xcapRpidActivity
        {
            /// <summary>
            /// The person has a calendar appointment, without specifying exactly of what type.  This activity is indicated if more detailed information is not available or the person chooses not to reveal more information.
            /// </summary>
            appointment,
            /// <summary>
            /// 
            /// </summary>
            away,
            breakfast,
            busy,
            dinner,
            holiday,
            //in-transit - not implemented
            //looking-for-work - not implemented
            lunch,
            meal,
            meeting,
            //on-the-phone - not implemented
            other,
            performance,
            //performance-absence
            playing,
            presentation,
            shopping,
            sleeping,
            spectator,
            steering,
            travel,
            tv,
            unknown,
            vacation,
            working,
            worship
        }

        /// <summary>
        /// Supported Rpid elements.
        /// </summary>
        public enum xcapRpidSupportedElements
        {
            /// <summary>
            /// The <activities> status element enumerates what the person is doing.
            /// </summary>
            activities,
            /// <summary>
            /// An identifier that groups similar person elements, devices, or services.
            /// </summary>
            Class,
            /// <summary>
            /// A device identifier in a tuple references a <device> element, indicating that this device contributes to the service described by the tuple.
            /// </summary>
            deviceID,
            /// <summary>
            /// The <mood> status element indicates the mood of the person.
            /// </summary>
            mood,
            /// <summary>
            /// The <place-is> status element reports on the properties of the place the presentity is currently at, such as the levels of light and noise.
            /// </summary>
            place_is,
            /// <summary>
            /// The <place-type> status elements reports the type of place the person is located in, such as 'classroom' or 'home'.
            /// </summary>
            place_type,
            /// <summary>
            /// The <privacy> element distinguishes whether the communication service is likely to be observable by other parties.
            /// </summary>
            privacy,
            /// <summary>
            /// When a service is likely to reach a user besides the person associated with the presentity, the relationship indicates how that user relates to the person.
            /// </summary>
            relationship,
            /// <summary>
            /// The <service-class> element describes whether the service is delivered electronically, is a postal or delivery service, or describes in-person communications.
            /// </summary>
            service_class,
            /// <summary>
            /// The <sphere> element characterizes the overall current role of the presentity.
            /// </summary>
            sphere,
            /// <summary>
            /// The <status-icon> element depicts the current status of the person or service.
            /// </summary>
            status_icon,
            /// <summary>
            /// The <time-offset> status element quantifies the time zone the person is in, expressed as the number of minutes away from UTC.
            /// </summary>
            time_offset,
            /// <summary>
            /// The <user-input> element records the user-input or usage state of the service or device, based on human user input.
            /// </summary>
            user_input
        }

        /// <summary>
        /// Elements which xcapRpidSupportedElements MAY be applied on.
        /// </summary>
        public enum xcapRpidSupportingElements
        {
            from_until,
            note,
            person,
            tuple,
            device
        }

        public enum xcapRpidPlaceIsType
        {
            audio,
            video,
            text // boh vie ci je to text
        }

        public enum xcapRpidPlaceIsAudio
        {
            /// <summary>
            /// The person is in a place with a level of background noise that makes audio communications difficult.
            /// </summary>
            noisy,
            /// <summary>
            /// The environmental conditions are suitable for audio communications.
            /// </summary>
            ok,
            /// <summary>
            /// The person is in a place such as a library, restaurant, place of worship, or theater that discourages noise, conversation, and other distractions.
            /// </summary>
            quiet,
            /// <summary>
            /// The place attributes for audio are unknown.
            /// </summary>
            unknown
        }

        public enum xcapRpidPlaceIsVideo
        {
            /// <summary>
            /// The person is in a bright place, sufficient for good rendering on video.
            /// </summary>
            toobright,
            /// <summary>
            /// The environmental conditions are suitable for video.
            /// </summary>
            ok,
            /// <summary>
            /// The person is in a dark place, and thus the camera may not be able to capture a good image.
            /// </summary>
            dark,
            /// <summary>
            /// The place attributes for video are unknown.
            /// </summary>
            unknown
        }

        public enum xcapRpidPlaceIsText
        {
            /// <summary>
            /// Typing or other text entry is uncomfortable.
            /// </summary>
            uncomfortable,
            /// <summary>
            /// Typing or other text entry is inappropriate, e.g., since the user is in a vehicle or house of worship.
            /// </summary>
            inappropriate,
            /// <summary>
            /// The environmental conditions are suitable for text-based communications.
            /// </summary>
            ok,
            /// <summary>
            /// The place attributes for text are unknown.
            /// </summary>
            unknown
        }

        public enum xcapRpidPlaceIsOptions
        {
            noisy,
            quiet,
            ok,
            unknown,
            toobright,
            dark,
            unfomfortable,
            inappropriate
        }

        /// <summary>
        /// CIPID supported elements
        /// </summary>
        public enum xcapCipidElement
        {
            /// <summary>
            /// URI pointing to a business card, in LDAP Data Interchange Format or vCard format.
            /// </summary>
            card,
            /// <summary>
            /// Includes the name identifying the tuple or
            /// person that the presentity suggests should be shown by the watcher
            /// user interface
            /// </summary>
            display_name,
            /// <summary>
            /// Provides a URI pointing to general information
            /// about the tuple or person, typically a web home page.
            /// </summary>
            homepage,
            /// <summary>
            /// URI pointing to an image (icon) representing the tuple or person.
            /// Supported formats are JPEG, PNG, GIF
            /// </summary>
            icon,
            /// <summary>
            /// Provides a URI pointing to a map related to the tuple or person.
            /// The map may be either an image, an HTML client-side image map, or a geographical
            /// information system (GIS) document, e.g., encoded as GML.
            /// </summary>
            map,
            /// <summary>
            /// URI pointing to a sound related to the tuple or person. MP3 and MIDI files are 
            /// supported.
            /// </summary>
            sound
        }

        /// <summary>
        /// RPID place-is element structure
        /// </summary>
        public struct xcapRpidPlaceIsElement
        {
            public xcapRpidPlaceIsType type;
            public List<xcapRpidPlaceIsOptions> options;
        }

        /// <summary>
        /// RPID element struct
        /// </summary>
        public struct xcapRpidElement
        {
            public xcapRpidSupportedElements element;
            public string nodeName;
            public XNamespace nameSpace;
            public List<xcapRpidSupportingElements> elementsAllowed;
        }

        /// <summary>
        /// PIDF element struct
        /// </summary>
        public struct xcapPidfElement
        {
            public xcapPidfSupportedElements element;
            public string nodeName;
            public XNamespace nameSpace;
            //iba pre <presence>
            public List<xcapPidfSupportedElements> elementsAllowed;
        }

        public struct xcapResourceListsElement
        {
            public xcapResourceListsSupportedElements element;
            public string nodeName;
            public XNamespace nameSpace;
        }

        public struct xcapPresRulesElement
        {
            public xcapPresRulesSupportedElements element;
            public string nodeName;
            public XNamespace nameSpace;
        }

        /// <summary>
        /// 
        /// </summary>
        public struct xcapElement
        {
            public XElement xelement;
            public XNamespace nameSpace;
            public xcapRpidSupportingElements allowed;
        }

        #endregion

        public class Xml
        {
            //An 'x' in the respective column indicates that the RPID element MAY appear as a child of that element.
            //+-----------------+------------+------+----------+---------+----------+
            //| Element         | From/until | Note | <person> | <tuple> | <device> |
            //|                 | ?          | ?    |          |         |          |
            //+-----------------+------------+------+----------+---------+----------+
            //| <activities>    |      x     |   x  |     x    |         |          |
            //| <class>         |            |      |     x    |    x    |     x    |
            //| <deviceID>      |            |      |          |    x    |          |
            //| <mood>          |      x     |   x  |     x    |         |          |
            //| <place-is>      |      x     |   x  |     x    |         |          |
            //| <place-type>    |      x     |   x  |     x    |         |          |
            //| <privacy>       |      x     |   x  |     x    |    x    |          |
            //| <relationship>  |            |   x  |          |    x    |          |
            //| <service-class> |            |   x  |          |    x    |          |
            //| <sphere>        |      x     |      |     x    |         |          |
            //| <status-icon>   |      x     |      |     x    |    x    |          |
            //| <time-offset>   |      x     |      |     x    |         |          |
            //| <user-input>    |            |      |     x    |    x    |     x    |
            //+-----------------+------------+------+----------+---------+----------+

            #region declarations
            /// <summary>
            /// stores xml data about "pidf-manipulation" document
            /// </summary>
            public XDocument xDocument;

            private string xmlVersion = "1.0";
            private string xmlEncoding = "utf-8";
            //private string xmlStandAlone = "yes";

            protected xcapBasicStatus _status;
            protected string _contact;
            protected string _note;
            protected string _user;

            #region properties;

            //public xcapBasicStatus Status
            //{
            //    set { _status = value; }
            //}
            //public string Contact
            //{
            //    set { _contact = value; }
            //}
            //public string Note
            //{
            //    set { _note = value; }
            //}
            public string User
            {
                set
                {
                    if (value != null)
                    {
                        _user = value;
                    }
                    //error - nezadal usera
                    else
                    {
                        throw new NotImplementedException("nezadal usera");
                    }
                }
            }
            #endregion

            #region struct elements

            protected xcapPidfElement sePresence;
            protected xcapPidfElement seTuple;
            protected xcapPidfElement sePerson;
            protected xcapPidfElement seDevice;
            protected xcapPidfElement seNote;
            protected xcapPidfElement seTimeStamp;

            protected xcapResourceListsElement seResourceLists;
            protected xcapResourceListsElement seList;
            protected xcapResourceListsElement seEntry;
            protected xcapResourceListsElement seDisplayName;

            protected xcapPresRulesElement seRuleSet;
            protected xcapPresRulesElement seRule;
            protected xcapPresRulesElement seActions;
            protected xcapPresRulesElement seConditions;
            protected xcapPresRulesElement seIdentity;
            protected xcapPresRulesElement seOne;
            protected xcapPresRulesElement seTransformations;
            protected xcapPresRulesElement seSubHandling;

            private xcapRpidElement seActivities;
            private xcapRpidElement seClass;
            private xcapRpidElement seDeviceID;
            private xcapRpidElement seMood;
            private xcapRpidElement sePlace_Is;
            private xcapRpidPlaceIsElement sePlace_Is_video;
            private xcapRpidPlaceIsElement sePlace_Is_audio;
            private xcapRpidPlaceIsElement sePlace_Is_text;
            private xcapRpidElement sePlace_Type;
            private xcapRpidElement sePrivacy;
            private xcapRpidElement seSphere;
            private xcapRpidElement seStatusIcon;
            private xcapRpidElement seUser_Input;

            #region not implemented yet
            //private xcapRpidElement seRelationship;
            //private xcapRpidElement seService_Class;
            //private xcapRpidElement seTime_Offset;
            #endregion

            #endregion

            #endregion;

            #region constructors

            public Xml(xcapDocument docType)
            {
                xDocument = new XDocument(new XDeclaration(xmlVersion, xmlEncoding, "yes"));
                //xDocument.Declaration = ;

                switch (docType)
                {
                    case xcapDocument.pidf:

                        #region declaring supported pidf/rpid elements

                        sePresence.element = xcapPidfSupportedElements.presence;
                        sePresence.nodeName = "presence";
                        sePresence.nameSpace = PI;
                        sePresence.elementsAllowed = new List<xcapPidfSupportedElements>();
                        sePresence.elementsAllowed.Add(xcapPidfSupportedElements.tuple);
                        sePresence.elementsAllowed.Add(xcapPidfSupportedElements.person);
                        sePresence.elementsAllowed.Add(xcapPidfSupportedElements.device);

                        seTuple.element = xcapPidfSupportedElements.tuple;
                        seTuple.nodeName = "tuple";
                        seTuple.nameSpace = PI;

                        sePerson.element = xcapPidfSupportedElements.person;
                        sePerson.nodeName = "person";
                        sePerson.nameSpace = DM;

                        seDevice.element = xcapPidfSupportedElements.device;
                        seDevice.nodeName = "device";
                        seDevice.nameSpace = DM;

                        seNote.element = xcapPidfSupportedElements.note;
                        seNote.nodeName = "note";
                        //nema namespace lebo sa dava priamo ako argument

                        seTimeStamp.element = xcapPidfSupportedElements.timestamp;
                        seTimeStamp.nodeName = "timestamp";
                        //namespace specifikuje priamo

                        seActivities.element = xcapRpidSupportedElements.activities;
                        seActivities.nodeName = "activities";
                        seActivities.nameSpace = RP;
                        seActivities.elementsAllowed = new List<xcapRpidSupportingElements>();
                        seActivities.elementsAllowed.Add(xcapRpidSupportingElements.person);
                        seActivities.elementsAllowed.Add(xcapRpidSupportingElements.note);
                        seActivities.elementsAllowed.Add(xcapRpidSupportingElements.from_until);

                        seClass.element = xcapRpidSupportedElements.Class;
                        seClass.nodeName = "class";
                        seActivities.nameSpace = RP;
                        seClass.elementsAllowed = new List<xcapRpidSupportingElements>();
                        seClass.elementsAllowed.Add(xcapRpidSupportingElements.person);
                        seClass.elementsAllowed.Add(xcapRpidSupportingElements.tuple);
                        seClass.elementsAllowed.Add(xcapRpidSupportingElements.device);

                        seDeviceID.element = xcapRpidSupportedElements.deviceID;
                        seDeviceID.nodeName = "deviceID";
                        seDeviceID.nameSpace = RP;
                        seDeviceID.elementsAllowed = new List<xcapRpidSupportingElements>();
                        seDeviceID.elementsAllowed.Add(xcapRpidSupportingElements.tuple);

                        seMood.element = xcapRpidSupportedElements.mood;
                        seMood.nodeName = "mood";
                        seMood.nameSpace = RP;
                        seMood.elementsAllowed = new List<xcapRpidSupportingElements>();
                        seMood.elementsAllowed.Add(xcapRpidSupportingElements.from_until);
                        seMood.elementsAllowed.Add(xcapRpidSupportingElements.note);
                        seMood.elementsAllowed.Add(xcapRpidSupportingElements.person);


                        sePlace_Is.element = xcapRpidSupportedElements.place_is;
                        sePlace_Is.nodeName = "place-is";
                        sePlace_Is.nameSpace = RP;
                        sePlace_Is.elementsAllowed = new List<xcapRpidSupportingElements>();
                        sePlace_Is.elementsAllowed.Add(xcapRpidSupportingElements.from_until);
                        sePlace_Is.elementsAllowed.Add(xcapRpidSupportingElements.note);
                        sePlace_Is.elementsAllowed.Add(xcapRpidSupportingElements.person);

                        #region Place Is declarations
                        sePlace_Is_audio.type = xcapRpidPlaceIsType.audio;
                        sePlace_Is_audio.options = new List<xcapRpidPlaceIsOptions>();
                        sePlace_Is_audio.options.Add(xcapRpidPlaceIsOptions.noisy);
                        sePlace_Is_audio.options.Add(xcapRpidPlaceIsOptions.quiet);
                        sePlace_Is_audio.options.Add(xcapRpidPlaceIsOptions.ok);
                        sePlace_Is_audio.options.Add(xcapRpidPlaceIsOptions.unknown);

                        sePlace_Is_video.type = xcapRpidPlaceIsType.video;
                        sePlace_Is_video.options = new List<xcapRpidPlaceIsOptions>();
                        sePlace_Is_video.options.Add(xcapRpidPlaceIsOptions.toobright);
                        sePlace_Is_video.options.Add(xcapRpidPlaceIsOptions.ok);
                        sePlace_Is_video.options.Add(xcapRpidPlaceIsOptions.dark);
                        sePlace_Is_video.options.Add(xcapRpidPlaceIsOptions.unknown);

                        sePlace_Is_text.type = xcapRpidPlaceIsType.text;
                        sePlace_Is_text.options = new List<xcapRpidPlaceIsOptions>();
                        sePlace_Is_text.options.Add(xcapRpidPlaceIsOptions.inappropriate);
                        sePlace_Is_text.options.Add(xcapRpidPlaceIsOptions.ok);
                        sePlace_Is_text.options.Add(xcapRpidPlaceIsOptions.dark);
                        sePlace_Is_text.options.Add(xcapRpidPlaceIsOptions.unknown);
                        #endregion

                        sePlace_Type.element = xcapRpidSupportedElements.place_type;
                        sePlace_Type.nodeName = "place-type";
                        sePlace_Type.nameSpace = RP;
                        sePlace_Type.elementsAllowed = new List<xcapRpidSupportingElements>();
                        sePlace_Type.elementsAllowed.Add(xcapRpidSupportingElements.from_until);
                        sePlace_Type.elementsAllowed.Add(xcapRpidSupportingElements.note);
                        sePlace_Type.elementsAllowed.Add(xcapRpidSupportingElements.person);

                        sePrivacy.element = xcapRpidSupportedElements.privacy;
                        sePrivacy.nodeName = "privacy";
                        sePrivacy.nameSpace = RP;
                        sePrivacy.elementsAllowed = new List<xcapRpidSupportingElements>();
                        sePrivacy.elementsAllowed.Add(xcapRpidSupportingElements.from_until);
                        sePrivacy.elementsAllowed.Add(xcapRpidSupportingElements.note);
                        sePrivacy.elementsAllowed.Add(xcapRpidSupportingElements.person);
                        sePrivacy.elementsAllowed.Add(xcapRpidSupportingElements.tuple);

                        seSphere.element = xcapRpidSupportedElements.sphere;
                        seSphere.nodeName = "sphere";
                        seSphere.nameSpace = RP;
                        seSphere.elementsAllowed = new List<xcapRpidSupportingElements>();
                        seSphere.elementsAllowed.Add(xcapRpidSupportingElements.from_until);
                        seSphere.elementsAllowed.Add(xcapRpidSupportingElements.person);


                        seStatusIcon.element = xcapRpidSupportedElements.status_icon;
                        seStatusIcon.nodeName = "status-icon";
                        seStatusIcon.nameSpace = RP;
                        seStatusIcon.elementsAllowed = new List<xcapRpidSupportingElements>();
                        seStatusIcon.elementsAllowed.Add(xcapRpidSupportingElements.from_until);
                        seStatusIcon.elementsAllowed.Add(xcapRpidSupportingElements.person);
                        seStatusIcon.elementsAllowed.Add(xcapRpidSupportingElements.tuple);

                        seUser_Input.element = xcapRpidSupportedElements.user_input;
                        seUser_Input.nodeName = "user-input";
                        seUser_Input.nameSpace = RP;
                        seUser_Input.elementsAllowed = new List<xcapRpidSupportingElements>();
                        seUser_Input.elementsAllowed.Add(xcapRpidSupportingElements.device);
                        seUser_Input.elementsAllowed.Add(xcapRpidSupportingElements.person);
                        seUser_Input.elementsAllowed.Add(xcapRpidSupportingElements.tuple);

                        #region not implemented yet
                    //seRelationship.element = xcapRpidSupportedElements.relationship;
                    //seService_Class.element = xcapRpidSupportedElements.service_class;
                    //seTime_Offset.element = xcapRpidSupportedElements.time_offset;
                    #endregion

                    #endregion
                    
                    break;

                    case xcapDocument.resourceLists:

                        #region declarign supported resource-lists elements

                        seResourceLists.element = xcapResourceListsSupportedElements.display_name;
                        seResourceLists.nameSpace = RL;
                        seResourceLists.nodeName = "resource-lists";

                        seList.element = xcapResourceListsSupportedElements.list;
                        seList.nameSpace = RL;
                        seList.nodeName = "list";

                        seEntry.element = xcapResourceListsSupportedElements.entry;
                        seEntry.nameSpace = RL;
                        seEntry.nodeName = "entry";

                        seDisplayName.element = xcapResourceListsSupportedElements.display_name;
                        seDisplayName.nameSpace = RL;
                        seDisplayName.nodeName = "display-name";

                        #endregion;

                    break;

                    case xcapDocument.presRules:

                    #region declaring suuported pres-rules elements

                        seRuleSet.element = xcapPresRulesSupportedElements.ruleset;
                        seRuleSet.nameSpace = CR;
                        seRuleSet.nodeName = "ruleset";

                        seRule.element = xcapPresRulesSupportedElements.rule;
                        seRule.nameSpace = CR;
                        seRule.nodeName = "rule";

                        seConditions.element = xcapPresRulesSupportedElements.conditions;
                        seConditions.nameSpace = CR;
                        seConditions.nodeName = "conditions";

                        seActions.element = xcapPresRulesSupportedElements.actions;
                        seActions.nameSpace = CR;
                        seActions.nodeName = "actions";

                        seTransformations.element = xcapPresRulesSupportedElements.transformations;
                        seTransformations.nameSpace = CR;
                        seTransformations.nodeName = "transformations";

                        seIdentity.element = xcapPresRulesSupportedElements.identity;
                        seIdentity.nameSpace = CR;
                        seIdentity.nodeName = "identity";

                        seOne.element = xcapPresRulesSupportedElements.one;
                        seOne.nameSpace = CR;
                        seOne.nodeName = "one";

                        seSubHandling.element = xcapPresRulesSupportedElements.sub_handling;
                        seSubHandling.nameSpace = PR;
                        seSubHandling.nodeName = "sub-handling";

                    #endregion

                    break;
                }

                
            }

            #endregion

            //povolene namespace
            /// <summary>
            /// Pidf xml namespace (urn:ietf:params:xml:ns:pidf:pidf)
            /// </summary>
            protected static XNamespace PI = "urn:ietf:params:xml:ns:pidf";
            /// <summary>
            /// Rpid xml namespace (urn:ietf:params:xml:ns:pidf:rpid)
            /// </summary>
            protected static XNamespace RP = "urn:ietf:params:xml:ns:pidf:rpid";
            /// <summary>
            /// Cipid xml namespace (urn:ietf:params:xml:ns:pidf:cipid)
            /// </summary>
            protected static XNamespace CI = "urn:ietf:params:xml:ns:pidf:cipid";
            /// <summary>
            /// Data-model xml namespace (urn:ietf:params:xml:ns:pidf:data-model)
            /// </summary>
            protected static XNamespace DM = "urn:ietf:params:xml:ns:pidf:data-model";
            /// <summary>
            /// Namespace for XML elements defined by RFC4589 to describe location types within XML documents (urn:ietf:params:xml:ns:location-type).
            /// </summary>
            protected static XNamespace PT = "urn:ietf:params:xml:ns:location-type";
            /// <summary>
            /// Resource lists xml namespace (urn:ietf:params:xml:ns:pidf:resource-lists)
            /// </summary>
            protected static XNamespace RL = "urn:ietf:params:xml:ns:resource-lists";
            /// <summary>
            /// Presence Authorization Rules xml namespace (urn:ietf:params:xml:ns:pres-rules)
            /// </summary>
            protected static XNamespace PR = "urn:ietf:params:xml:ns:pres-rules";
            /// <summary>
            /// Default Presence Authorization Rules xml namespace (urn:ietf:params:xml:ns:pres-rules)
            /// </summary>
            protected static XNamespace PRD = "urn:ietf:params:xml:ns:pres-rules";
            /// <summary>
            /// Common policy xml namespace (urn:ietf:params:xml:ns:common-policy)
            /// </summary>
            protected static XNamespace CR = "urn:ietf:params:xml:ns:common-policy";

            //atributy na namespace na definovanie xmlns v presence elemente
            protected XAttribute nsCipid = new XAttribute(XNamespace.Xmlns + "ci", CI.NamespaceName);
            protected XAttribute nsRpid = new XAttribute(XNamespace.Xmlns + "rp", RP.NamespaceName);
            protected XAttribute nsDataModel = new XAttribute(XNamespace.Xmlns + "dm", DM.NamespaceName);
            protected XAttribute nsLocationType = new XAttribute(XNamespace.Xmlns + "pt", PT.NamespaceName);
            //protected XAttribute nsPresRulesDefault = new XAttribute(XNamespace.Xmlns PRD.NamespaceName);
            protected XAttribute nsPresRules = new XAttribute(XNamespace.Xmlns + "pr", PR.NamespaceName);
            protected XAttribute nsCommonPolicy = new XAttribute(XNamespace.Xmlns + "cr", CR.NamespaceName);

            //<presence>
            protected XElement presence;

            //<resource-list>
            protected XElement resourceLists;

            //<ruleset>
            protected XElement presRules;


            protected void AddPresence()
            {
                XAttribute xaPresenceEntity = new XAttribute("entity", _user);
                presence = new XElement(sePresence.nameSpace + sePresence.nodeName);
                presence.Add(xaPresenceEntity);
                presence.Add(nsCipid);
                presence.Add(nsRpid);
                presence.Add(nsDataModel);
            }

            protected void AddResourceLists()
            {
                resourceLists = new XElement(seResourceLists.nameSpace + seResourceLists.nodeName);
            }

            protected void AddPresRules()
            {
                presRules = new XElement(seRuleSet.nameSpace + seRuleSet.nodeName);
                //presRules.Add(nsPresRulesDefault);
                presRules.Add(nsPresRules);
                presRules.Add(nsCommonPolicy);
            }

            protected XElement AddTuple(string id, xcapBasicStatus status, string contact, string priority, string note)
            {
                XElement tuple = new XElement(seTuple.nameSpace + seTuple.nodeName);
                XAttribute xaTupleId = new XAttribute("id", id);
                XElement xeTupleStatus = new XElement(PI + "status");
                XElement xeTupleStatusBasic = new XElement(PI + "basic");
                XElement xeTupleContact = new XElement(PI + "contact");
                XElement xeTupleTimestamp = new XElement(PI + "timestamp");

                //id
                tuple.Add(xaTupleId);

                //status 
                xeTupleStatusBasic.Add(status);
                xeTupleStatus.Add(xeTupleStatusBasic);
                tuple.Add(xeTupleStatus);

                //contact
                if (contact.Length > 0)
                {
                    if (priority.Length > 0)
                    {
                        XAttribute xaContactPriority;
                        xaContactPriority = new XAttribute("priority", priority);
                        xeTupleContact.Add(xaContactPriority);
                    }
                    xeTupleContact.Add(contact);
                    tuple.Add(xeTupleContact);
                }

                //note
                if (note.Length > 0)
                {
                    AddNote(tuple, PI, note);
                }

                return tuple;
            }

            protected XElement AddPerson(string id, string note)
            {
                XElement person = new XElement(sePerson.nameSpace + sePerson.nodeName);
                XAttribute xaPersonId = new XAttribute("id", id);

                //id
                person.Add(xaPersonId);

                //person zrejme nema status

                //note
                if (note.Length != 0)
                {
                    AddNote(person, DM, note);
                }

                return person;
            }

            protected XElement AddDevice(string id, string deviceId, xcapBasicStatus status, string note)
            {
                XElement device = new XElement(seDevice.nameSpace + seDevice.nodeName);
                XAttribute xaDeviceId = new XAttribute("id", id);
                XElement xeDeviceStatus = new XElement(seDevice.nameSpace + "status");
                XElement xeDeviceStatusBasic = new XElement(seDevice.nameSpace + "basic");
                XElement xeDeviceId = new XElement(seDevice.nameSpace + "device-id");

                //id
                device.Add(xaDeviceId);

                //status
                xeDeviceStatusBasic.Add(status);
                xeDeviceStatus.Add(xeDeviceStatusBasic);
                device.Add(xeDeviceStatus);

                //note
                if (note.Length != 0)
                {
                    AddNote(device, DM, note);
                }

                return device;
            }

            protected void AddNote(XElement el, XNamespace ns, string text)
            {
                XElement note = new XElement(ns + seNote.nodeName);
                note.Add(text);
                el.Add(note);
            }


            protected XElement AddRule(string id)
            {
                XElement rule = new XElement(seRule.nameSpace + seRule.nodeName);
                XAttribute xaRuleId = new XAttribute("id", id);

                //id
                rule.Add(xaRuleId);

                return rule;
            }

            protected void AddOne(XElement el, string uri)
            {
                XAttribute id = new XAttribute("id", uri);
                XElement one = new XElement(seOne.nameSpace + seOne.nodeName);
                one.Add(id);
                el.Add(one);
            }

            protected void AddTransformations(XElement el, bool provideAllRpid)
            {
                XElement transformations = new XElement(seTransformations.nameSpace + seTransformations.nodeName);

                XElement provideServices = new XElement(PR + "provide-services");
                XElement provideServicesAll = new XElement(PR + "all-services");
                provideServices.Add(provideServicesAll);
                transformations.Add(provideServices);

                XElement providePersons = new XElement(PR + "provide-persons");
                XElement providePersonsAll = new XElement(PR + "all-persons");
                providePersons.Add(providePersonsAll);
                transformations.Add(providePersons);

                XElement provideDevices = new XElement(PR + "provide-devices");
                XElement provideDevicesAll = new XElement(PR + "all-devices");
                provideDevices.Add(provideDevicesAll);
                transformations.Add(provideDevices);
                
                //rpid elements
                if (provideAllRpid == true)
                {
                    //ozelene kvoli mobile verzii
                    //TODO: prerobit inym sposobom, nepovoli .GetValues()
                    //foreach (xcapRpidSupportedElements item in Enum.GetValues(typeof(xcapRpidSupportedElements)))
                    //{
                    //    string value = item.ToString();
                    //    //ak obsahuje podjebovnik, nahradit pomlckou
                    //    if (value.Contains("_"))
                    //    {
                    //        value = item.ToString().Replace("_", "-");
                    //    }
                    //    else if (item == xcapRpidSupportedElements.Class)
                    //    {
                    //        value = "class";
                    //    }
                    //    XElement element = new XElement(PR + "provide-" + value);
                    //    element.Add("true");
                    //    transformations.Add(element);
                    //}
                }

                el.Add(transformations);
            }

            /// <summary>
            /// Create new list element
            /// </summary>
            /// <param name="name">Name of the list</param>
            /// <returns></returns>
            protected XElement AddList(string name, string _displayName)
            {
                XElement resLists = new XElement(seList.nameSpace + seList.nodeName);
                XElement displayName = new XElement(seDisplayName.nameSpace + seDisplayName.nodeName);
                XAttribute xaName = new XAttribute("name", name);
                resLists.Add(xaName);
                displayName.Add(_displayName);
                resLists.Add(displayName);

                return resLists;
            }

            /// <summary>
            /// Add a resource-list ENTRY element
            /// </summary>
            /// <param name="el">Add to specified element</param>
            /// <param name="uri">Entry uri</param>
            /// <param name="name">Entry display name</param>
            protected void AddEntry(XElement el, string _uri, string _name)
            {
                XElement entry = new XElement(seEntry.nameSpace + seEntry.nodeName);
                XAttribute uri = new XAttribute("uri", _uri);
                XElement displayName = new XElement(seDisplayName.nameSpace + seDisplayName.nodeName);
                displayName.Add(_name);
                entry.Add(uri);
                entry.Add(displayName);
                el.Add(entry);
            }


            /// <summary>
            /// Contains a string indicating the date and
            /// time of the status change of this tuple.  The value of this element
            /// MUST follow the IMPP datetime format [RFC3339].
            /// </summary>
            /// <param name="el">Add to element</param>
            /// <param name="ns">Specify namespace to use</param>
            /// <param name="timestamp">Timestamp must follow IMPP datetime format, e.g. 2008-11-21T09:00:00+05:00</param>
            protected void AddTimeStamp(XElement el, XNamespace ns, string timestamp)
            {
                XElement elTimestamp = new XElement(ns + seTimeStamp.nodeName);
                elTimestamp.Add(timestamp);
                el.Add(elTimestamp);
            }

            /// <summary>
            /// The <activities> element describes what the person is currently doing, expressed as an enumeration of activity-describing elements.
            /// </summary>
            /// <param name="element">Add to element</param>
            /// <param name="activities">Supports multiple activities</param>
            /// <param name="other">Value of other activity</param>
            /// <param name="note">Standard note</param>
            public void rpidActivities(xcapElement element, xcapRpidActivity[] activities, string other, string note)
            {
                //skontroluje ci je povolene na dany element
                if (seActivities.elementsAllowed.Contains(element.allowed))
                {
                    //<activities> rpid element
                    XElement xeRpidActivity = new XElement(RP + seActivities.nodeName);

                    //ak je povolena poznamka
                    if (seActivities.elementsAllowed.Contains(xcapRpidSupportingElements.note))
                    {
                        if (note.Length != 0)
                        {
                            AddNote(xeRpidActivity, RP, note);
                        }
                    }

                    foreach (xcapRpidActivity item in activities)
                    {
                        if (item != xcapRpidActivity.other)
                        {
                            //</activity> samotny element
                            XElement xeRpidSpecAct = new XElement(RP + item.ToString());
                            xeRpidActivity.Add(xeRpidSpecAct);
                        }
                        else
                        {
                            XElement xeRpidSpecAct = new XElement(RP + "other");
                            xeRpidSpecAct.Add(other);
                            xeRpidActivity.Add(xeRpidSpecAct);
                        }
                    }

                    element.xelement.Add(xeRpidActivity);
                }
                else
                {
                    //error - docasne poriesene
                    element.xelement.Add(new XElement(PI + "error", "activities not implemented on this element"));
                }
            }

            /// <summary>
            /// The presentity can use this information to group similar services,
            /// devices, or person elements or to convey information that the
            /// presence agent can use for filtering or authorization.
            /// Each element (tuple, service, device) can have 1 class element
            /// TODO:
            /// zrejme ten namespace je vzdy RP
            /// </summary>
            /// <param name="element">Element in which class is being added</param>
            /// <param name="nameSpace">Specified element's namespace</param>>
            /// <param name="value">Value to set</param>
            public void rpidClass(xcapElement element, XNamespace nameSpace, string value)
            {
                if (seClass.elementsAllowed.Contains(element.allowed))
                {
                    //<class> rpid Mood element
                    XElement xeRpidClass = new XElement(nameSpace + seClass.nodeName);
                    xeRpidClass.Add(value);
                    element.xelement.Add(xeRpidClass);
                }
                else
                {
                    //error - docasne poriesene
                    element.xelement.Add(new XElement(PI + "error", "class not implemented on this element"));
                }
            }

            /// <summary>
            /// The <deviceID> element in the <tuple> element references the device that provides a particular service.
            /// </summary>
            /// <param name="element"></param>
            /// <param name="value"></param>
            public void rpidDeviceID(xcapElement element, string value)
            {
                if (seDeviceID.elementsAllowed.Contains(element.allowed))
                {
                    //<class> rpid Mood element
                    XElement xeRpidDevice = new XElement(seDeviceID.nameSpace + seDeviceID.nodeName);
                    xeRpidDevice.Add(value);
                    element.xelement.Add(xeRpidDevice);
                }
                else
                {
                    //error - docasne poriesene
                    element.xelement.Add(new XElement(PI + "error", "class not implemented on this element"));
                }
            }

            /// <summary>
            /// Adds <mood> element to specified XElement
            /// </summary>
            /// <param name="element">Element in which mood is being added</param>
            /// <param name="moods">allowed moods enumeration</param>
            public void rpidMood(xcapElement element, xcapRpidMood[] moods, string note)
            {
                if (seMood.elementsAllowed.Contains(element.allowed))
                {

                    //<mood> rpid Mood element
                    XElement xeRpidMood = new XElement(seMood.nameSpace + seMood.nodeName);

                    if (note.Length > 0)
                    {
                        AddNote(xeRpidMood, RP, note);
                    }

                    foreach (xcapRpidMood item in moods)
                    {
                        //</mood> samotny element
                        XElement xeRpidSpecMood = new XElement(RP + item.ToString());
                        xeRpidMood.Add(xeRpidSpecMood);
                    }

                    element.xelement.Add(xeRpidMood);
                }
                else
                {
                    //error - docasne poriesene
                    element.xelement.Add(new XElement(PI + "error", "class not implemented on this element"));
                }
            }

            /// <summary>
            /// The <place-is> element describes properties of the place the person
            /// is currently at.  This offers the watcher an indication of what kind
            /// of communication is likely to be successful.  Each major media type
            /// has its own set of attributes.  Omitting the element indicates that
            /// the property is unknown. 
            /// </summary>
            /// <param name="element">Add to this element</param>
            /// <param name="elementType">Specify element type of "element"</param>
            /// <param name="audio">Allowed audio options</param>
            /// <param name="video">Allowed video options</param>
            /// <param name="text">Allowed text options</param>
            /// <param name="note">Note string</param>
            public void rpidPlaceIs(xcapElement element, xcapRpidPlaceIsAudio audio, xcapRpidPlaceIsVideo video, xcapRpidPlaceIsText text, string note)
            {
                bool displayPlaceIsTag = false; //ak je stale false tak nezobrazi tag placeis

                if (sePlace_Is.elementsAllowed.Contains(element.allowed))
                {
                    XElement elPlaceIs = new XElement(sePlace_Is.nameSpace + sePlace_Is.nodeName);
                    if (note.Length > 0)
                    {
                        AddNote(elPlaceIs, RP, note);
                    }

                    //<audio>
                    if (sePlace_Is_audio.options.Contains((xcapRpidPlaceIsOptions)audio))
                    {
                        XElement elPlaceIsAudio = new XElement(sePlace_Is.nameSpace + "audio");
                        XElement elPlaceIsAudioValue = new XElement(sePlace_Is.nameSpace + audio.ToString());
                        elPlaceIsAudio.Add(elPlaceIsAudioValue);
                        elPlaceIs.Add(elPlaceIsAudio);

                        displayPlaceIsTag = true;
                    }

                    //<video>
                    if (sePlace_Is_video.options.Contains((xcapRpidPlaceIsOptions)video))
                    {
                        XElement elPlaceIsAudio = new XElement(sePlace_Is.nameSpace + "video");
                        XElement elPlaceIsAudioValue = new XElement(sePlace_Is.nameSpace + video.ToString());
                        elPlaceIsAudio.Add(elPlaceIsAudioValue);
                        elPlaceIs.Add(elPlaceIsAudio);

                        displayPlaceIsTag = true;
                    }

                    //<text>
                    if (sePlace_Is_text.options.Contains((xcapRpidPlaceIsOptions)text))
                    {
                        XElement elPlaceIsAudio = new XElement(sePlace_Is.nameSpace + "text");
                        XElement elPlaceIsAudioValue = new XElement(sePlace_Is.nameSpace + text.ToString());
                        elPlaceIsAudio.Add(elPlaceIsAudioValue);
                        elPlaceIs.Add(elPlaceIsAudio);

                        displayPlaceIsTag = true;
                    }

                    if (displayPlaceIsTag == true)
                        element.xelement.Add(elPlaceIs);
                }
                else
                {
                    //error - docasne poriesene
                    element.xelement.Add(new XElement(PI + "error", "class not implemented on this element"));
                }
            }

            /// <summary>
            /// The <place-type> element describes the type of place the person is currently at.
            /// </summary>
            /// <param name="element"></param>
            /// <param name="locations">Allowed locations</param>
            /// <param name="note">Standard note element</param>
            /// <param name="other">Sets a value of "other" element</param>
            public void rpidPlaceType(xcapElement element, xcapLocationTypes[] locations, string note, string other)
            {
                if (sePlace_Is.elementsAllowed.Contains(element.allowed))
                {
                    //vlozime namespace pre place-type
                    presence.Add(nsLocationType);

                    //<place-type> rpid element
                    XElement elPlaceType = new XElement(sePlace_Type.nameSpace + sePlace_Type.nodeName);

                    if (note.Length > 0)
                    {
                        AddNote(elPlaceType, RP, note);
                    }

                    foreach (xcapLocationTypes item in locations)
                    {
                        XElement elPlaceTypeSpecify = new XElement(PT + item.ToString());

                        if (item != xcapLocationTypes.other)
                        {
                            //</place> samotny element    
                            elPlaceType.Add(elPlaceTypeSpecify);
                        }
                        else
                        {
                            //<other>valie</other>
                            elPlaceTypeSpecify.Add(other);
                            elPlaceType.Add(elPlaceTypeSpecify);
                        }
                    }

                    element.xelement.Add(elPlaceType);
                }
            }

            /// <summary>
            /// The <privacy> element indicates which types of communication third
            /// parties in the vicinity of the presentity are unlikely to be able to
            /// intercept accidentally or intentionally.
            /// </summary>
            /// <param name="element">Add to this element</param>
            /// <param name="policies">Allowed policies</param>
            /// <param name="note">Standard note</param>
            public void rpidPrivacy(xcapElement element, xcapRpidPrivacy[] privacies, string note)
            {
                if (sePrivacy.elementsAllowed.Contains(element.allowed))
                {
                    //<privacy> rpid element
                    XElement elPrivacy = new XElement(sePlace_Type.nameSpace + sePrivacy.nodeName);

                    if (note.Length > 0)
                    {
                        AddNote(elPrivacy, RP, note);
                    }

                    foreach (xcapRpidPrivacy item in privacies)
                    {
                        XElement elPrivacySpecify = new XElement(RP + item.ToString());
                        elPrivacy.Add(elPrivacySpecify);
                    }

                    element.xelement.Add(elPrivacy);
                }
            }

            /// <summary>
            /// The <sphere> element designates the current state and role that the person plays.
            /// TODO: zistil som, ide to <sphere>value</sphere> opravit!!!!
            /// </summary>
            /// <param name="element">Add to this element</param>
            /// <param name="sphere">Predefined spheres</param>
            /// <param name="other">Custom sphere element</param>
            public void rpidSphere(xcapElement element, xcapRpidSphere sphere, string other)
            {
                if (seSphere.elementsAllowed.Contains(element.allowed))
                {
                    //<sphere> rpid element
                    XElement elSphere = new XElement(seSphere.nameSpace + seSphere.nodeName);
                    XElement elSphereSpecify;

                    //ak zada other tak vytvori tag </other>
                    if (other.Length > 0)
                    {
                        //ak nastane chyba, napriklad ze vlozi biely znak alebo tak
                        //tak vlozi unknown element automaticky bez upozornenia
                        //toto sa asi malo robit cez <other>value</other>
                        try
                        {
                            elSphereSpecify = new XElement(RP + other);
                        }
                        catch (System.Xml.XmlException)
                        {
                            elSphereSpecify = new XElement(RP + xcapRpidSphere.unknown.ToString());
                        }

                    }
                    //inak bude klasicky z ponuky
                    else
                    {
                        elSphereSpecify = new XElement(RP + sphere.ToString());
                    }

                    elSphere.Add(elSphereSpecify);
                    element.xelement.Add(elSphere);
                }
            }

            /// <summary>
            /// The <status-icon> element includes a URI pointing to an image (icon)
            /// representing the current status of the person or service.
            /// </summary>
            /// <param name="element">Add to this element</param>
            /// <param name="uri">URI of an icon</param>
            public void rpidStatusIcon(xcapElement element, string uri)
            {
                if (seStatusIcon.elementsAllowed.Contains(element.allowed))
                {
                    //<class> rpid Mood element
                    XElement xeRpidIcon = new XElement(seStatusIcon.nameSpace + seStatusIcon.nodeName);
                    xeRpidIcon.Add(uri);
                    element.xelement.Add(xeRpidIcon);
                }
                else
                {
                    //error - docasne poriesene
                    element.xelement.Add(new XElement(PI + "error", "class not implemented on this element"));
                }
            }

            /// <summary>
            /// The <user-input> element records the user-input or usage state of the
            /// service or device, based on human user input, e.g., keyboard,
            /// pointing device, or voice.
            /// </summary>
            /// <param name="element">Add to this element</param>
            /// <param name="input">Idle or active</param>
            /// <param name="idle_treshold">records how long the presentity will wait before reporting the service or device to be idle, measured in seconds.</param>
            /// <param name="last_input">element may be used by a watcher, typically in combination with other data, to estimate how likely a user is to answer when contacting the service.</param>
            public void rpidUserInput(xcapElement element, xcapRpidUserInput input, string idle_treshold, string last_input)
            {
                if (seUser_Input.elementsAllowed.Contains(element.allowed))
                {
                    XElement xeRpidUserInput = new XElement(seUser_Input.nameSpace + seUser_Input.nodeName);
                    XAttribute xaRpidUserInputIdleTreshold = new XAttribute("idle-treshold", idle_treshold);
                    XAttribute xaRpidUserInputLastInput = new XAttribute("last-input", last_input);

                    xeRpidUserInput.Add(xaRpidUserInputIdleTreshold);
                    xeRpidUserInput.Add(xaRpidUserInputLastInput);
                    xeRpidUserInput.Add(input);
                    element.xelement.Add(xeRpidUserInput);
                }
                else
                {
                    //error - docasne poriesene
                    element.xelement.Add(new XElement(PI + "error", "class not implemented on this element"));
                }
            }

            #region Not implemented rpid methods

            /// <summary>
            /// Not implemented yet.
            /// </summary>
            private void rpidRelationship()
            {
                throw new NotImplementedException();
            }

            /// <summary>
            /// Not implemented yet.
            /// </summary>
            private void rpidServiceClass()
            {
                throw new NotImplementedException();
            }

            /// <summary>
            /// Not implemented yet.
            /// </summary>
            private void rpidTimeOffset()
            {
                throw new NotImplementedException();
            }


            #endregion
            
            /// <summary>
            /// Add a cipid element to a xcapElement.element
            /// </summary>
            /// <param name="element">Add to element</param>
            /// <param name="cipid">Specify cipid element</param>
            /// <param name="uri">Adds uri</param>
            public void cipidElement(xcapElement element, xcapCipidElement cipid, string uri)
            {
                XElement value = new XElement(cipid.ToString());
                //if (element.xelement.Elements().Contains(value))
                //{
                //    Console.WriteLine(cipid.ToString());
                //};
                    
                string nodeName = cipid.ToString();

                //osetrim ak je display_name aby bolo - namiesto _
                if (cipid == xcapCipidElement.display_name)
                {
                    nodeName = "display-name";
                }

                //<class> rpid Mood element
                XElement xeElement = new XElement(CI + nodeName);
                xeElement.Add(uri);
                element.xelement.Add(xeElement);
            }

            protected string ResLists()
            {
                return "";
            }

            protected XDocument Pidf()
            {          
                AddPresence();

                XElement tuple = AddTuple("23kji", _status, _contact, "0.8", _note);
                //XElement tuple2 = AddTuple("23akji", xcapBasicStatus.open, "9098093", "0.8", "toto eje iny pomocny tuple");
                XElement person = AddPerson("uhjh", "this is person note element!!!");
                XElement device = AddDevice("kjhou8", "ID-8976-CAL", xcapBasicStatus.open, "helo world!");

                //zadefinujeme velke objekty
                xcapElement xcapTuple;
                xcapTuple.xelement = tuple;
                xcapTuple.nameSpace = PI;
                xcapTuple.allowed = xcapRpidSupportingElements.tuple;

                xcapElement xcapPerson;
                xcapPerson.xelement = person;
                xcapPerson.nameSpace = DM;
                xcapPerson.allowed = xcapRpidSupportingElements.person;


                rpidDeviceID(xcapTuple, "DEVICe ID 232lk");

                rpidClass(xcapTuple, PI, "auth-1");

                xcapRpidActivity[] acInput = { xcapRpidActivity.holiday, xcapRpidActivity.vacation, xcapRpidActivity.steering, xcapRpidActivity.other };
                rpidActivities(xcapPerson, acInput, "hokej", "kodim tuto bakalarku");

                xcapRpidMood[] moInput = { xcapRpidMood.bored, xcapRpidMood.worried };
                rpidMood(xcapPerson, moInput, "boli ma hlava");

                rpidPlaceIs(xcapPerson, xcapRpidPlaceIsAudio.noisy, xcapRpidPlaceIsVideo.dark, xcapRpidPlaceIsText.ok, "lampa v izbe");

                xcapLocationTypes[] ptInput = { xcapLocationTypes.other, xcapLocationTypes.industrial };
                rpidPlaceType(xcapPerson, ptInput, "poznamkaaa", "postel na intraku");

                xcapRpidPrivacy[] poInput = { xcapRpidPrivacy.audio, xcapRpidPrivacy.video };
                rpidPrivacy(xcapTuple, poInput, string.Empty);

                rpidSphere(xcapPerson, xcapRpidSphere.home, "scouting");

                rpidStatusIcon(xcapTuple, "http://www.example.com/");

                rpidUserInput(xcapPerson, xcapRpidUserInput.active, "600", "dnes :)");

                AddTimeStamp(tuple, PI, "9809342093");

                cipidElement(xcapPerson, xcapCipidElement.display_name, "http://ra2tour.sk/");
                cipidElement(xcapPerson, xcapCipidElement.card, "http://ra2tour.sk/");

                presence.Add(tuple);
                //presence.Add(tuple2);
                presence.Add(person);
                presence.Add(device);
                //pidf.Save(@"C:\ahoj.xml");

                xDocument.Add(presence);

                return xDocument;
            }

        }

    }
}